package cn.zxyh.service.impl;

import cn.zxyh.mapper.BankCardMapper;
import cn.zxyh.mapper.UserMapper;
import cn.zxyh.pojo.BankCard;
import cn.zxyh.pojo.User;
import cn.zxyh.service.LoginService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;


@Service
public class LoginSeviceImpl implements LoginService {
    @Resource
    UserMapper userMapper;
    @Resource
    BankCardMapper bankCardMapper;

    @Override
    public User login(String username, String password) {
        return userMapper.login(username, password);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public int regist(String username, String password, String cardNumber, String payPassword) {
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        user.setCardNumber(cardNumber);
        System.out.println(user);
        userMapper.addUser(user);
        BankCard bankCard = new BankCard();
        bankCard.setBalance(1000);
        bankCard.setCardNumber(cardNumber);
        bankCard.setPassword(payPassword);
        bankCard.setUserId(user.getId());
        bankCardMapper.addBandCard(bankCard);
        return 0;
    }
}
